package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.controller.generateRFC;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.controller.database.DatabaseConnection;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.model.RFC;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.GenerateRFCPanel;

public class DeleteRFCThread extends Thread {

	private GenerateRFCPanel generateRFCPanel;
	private DatabaseConnection connection;

	public DeleteRFCThread(GenerateRFCPanel generateRFCPanel) {
		this.generateRFCPanel = generateRFCPanel;
	}

	@Override
	public void run() {
		this.connection = new DatabaseConnection();
		this.connection.connect();

		
		String id = this.generateRFCPanel.getDatainputPanel().getLb_IDValue().getText();
		String query = "DELETE FROM CMS_RFC WHERE "+ RFC.TC_ID+" = '"+id+"'";
		
		try {
			
			connection.insertquery(query);
			
			this.generateRFCPanel.getFunctionPanel().changeButtonstate();
			
			this.generateRFCPanel.setVisible(false);
			this.generateRFCPanel.getDatainputPanel().removeAllPanles();
			this.generateRFCPanel.setVisible(true);
		} catch (Exception e) {
		}
		this.connection.disconnect();
	}

}
